package com.settlement.system.controller;

import com.settlement.system.csv.CsvExportBuilder;
import com.settlement.system.csv.CsvExportUtil;
import com.settlement.system.common.enums.ExcelFileType;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.csv.DateSpiltCsvDatas;
import com.settlement.system.common.util.common.FasUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.settlement.system.model.entity.common.TblJlqcFinanceDetail;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import com.settlement.system.service.ITblJlqcFinanceDetailService;

import java.io.File;
import java.util.Map;

/**
 * 巨量千川财务流水 前端控制器
 * @author lwb
 * @since 2023-12-26
 */

@Api(tags = "巨量千川财务流水",description = "巨量千川财务流水")
@RestController
@RequestMapping("/tbl-jlqc-finance-detail")
public class TblJlqcFinanceDetailController extends ExcelController<TblJlqcFinanceDetail> {

    @Value("${system.export-root.path}")
    private String exportRootPath;

    @Resource
    private ITblJlqcFinanceDetailService tblJlqcFinanceDetailService;

    @Override
    public IBaseService init() {
        return tblJlqcFinanceDetailService;
    }

    @Override
    protected void setParamsModel(Map<String, Object> model) {
        FasUtil.formatInQueryCondition(model,"shopNo");
        super.setParamsModel(model);
    }
    @Override
    protected void setFootModel(Map<String, Object> result, Map<String, Object> model) throws ServiceException {
        result.put("foot",tblJlqcFinanceDetailService.getFoot(model));
    }

    @Override
    public Class<?> getModelClass() {
        return TblJlqcFinanceDetail.class;
    }

    @Override
    public void exportExcelPost(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params) throws Exception {
        setParamsModel(params);
        String fileName = "巨量千川财务流水账单";
        String path = exportRootPath + System.currentTimeMillis() + File.separator;
        CsvExportUtil.createCsv()
                .headClass(getModelClass())
                .fileName(fileName)
                .fileType(ExcelFileType.XLSX)
                .model(CsvExportBuilder.MULTI_ZIP_MODEL)
                .parentPath(path)
                .csvDatas(new DateSpiltCsvDatas(init(), params))
                .export(request, response);
    }


}

